package com.example.demo.controller;

import java.util.Date;

import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.model.SysUserModel;
import com.example.demo.service.UserService;

@RestController
@RequestMapping("/user")
public class UserController {

	private static final Logger logger = LoggerFactory.getLogger(UserController.class);	
 
	@Autowired
	UserService userService;

	@RequestMapping("/list")
	public Page<SysUserModel> queryUserPage(String pageNo,String pageSize) {
		logger.info("查询系统用户分页...");
		//TestUser user = new TestUser();
		//user.setUser("111111111");
		//return user.getUser();
		return userService.queryUserPage(NumberUtils.toInt(pageNo),NumberUtils.toInt(pageSize));
	}
	
	
	 
	
	 
	
	@PostMapping("add")
	public String saveUser(SysUserModel user) {
		logger.info("查询系统用户分页...");
		user.setCreateTime(new Date());
		userService.saveUser(user);
		return "1";
	}
	
	
	
	
	@GetMapping("existLoginName")
	public int existLoginName(String loginName) {
		logger.info("查询是否有登录账号...");
		return userService.existLoginName(loginName);
	}
	
	
	
	
	
	
	
	
	
	
}